package com.dx.handler;

import com.dx.exception.PermissionVerifyException;
import com.dx.exception.UserNotAcctivationException;
import com.dx.exception.UserNotExistException;
import io.netty.handler.codec.http.HttpResponseStatus;
import lombok.extern.slf4j.Slf4j;
import com.dx.result.R;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.sql.SQLIntegrityConstraintViolationException;

/*
 * 全局异常处理类
 * 自动将返回结果序列化为json
 */
@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {
    @ExceptionHandler
    R<String> userNotExistExceptionHandeler(UserNotExistException userNotExistException){
        return R.fail("用户不存在");
    }
    @ExceptionHandler
    R<String> userNotAcctivationExceptionHandeler(UserNotAcctivationException userNotAcctivationException){
        return R.fail("账号未激活");
    }
//    @ExceptionHandler(value = BaseException.class)
    @ExceptionHandler
    R<String> exceptionHandeler(RuntimeException runtimeException){
        log.info("进入全局异常捕获类");
        log.info(runtimeException.getMessage());
        return R.fail("失败");
    }
    @ExceptionHandler
    R<?> PermissionExceptionHandeler(PermissionVerifyException permissionVerifyException){
        return  R.fail(HttpResponseStatus.FORBIDDEN.code(),"权限不足");
    }



}
